package cn.sczhyt.modules.szhy.controller;

import java.io.FileNotFoundException;
import java.util.Arrays;
import java.util.List;
import java.util.Map;

import cn.sczhyt.common.utils.UploadFileUtils;
import cn.sczhyt.modules.szhy.entity.MeetingNoticeReceiveEntity;
import cn.sczhyt.modules.szhy.entity.VO.MeetingNoticeEntitySaveVO;
import cn.sczhyt.modules.szhy.service.MeetingNoticeReceiveService;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import cn.sczhyt.modules.szhy.entity.MeetingNoticeEntity;
import cn.sczhyt.modules.szhy.service.MeetingNoticeService;
import cn.sczhyt.common.utils.PageUtils;
import cn.sczhyt.common.utils.R;
import org.springframework.web.multipart.MultipartFile;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;


/**
 * 通知表
 *
 * @author luojialin
 * @email 78357966@qq.com
 * @date 2021-04-02 10:15:15
 */
@Api(tags = "PC消息发布模块")
@RestController
@RequestMapping("szhy/meetingnotice")
public class MeetingNoticeController {
    @Autowired
    private MeetingNoticeService meetingNoticeService;

    /**
     * 列表
     */
    @RequestMapping("/list")
    public R list(@RequestParam Map<String, Object> params){

        PageUtils page = meetingNoticeService.queryPage(params);

        return R.ok().put("page", page);
    }


    /**
     * 查看信息内容
     */
    @RequestMapping("/info/{noticeId}")
    public R info(@PathVariable("noticeId") String noticeId){

		MeetingNoticeEntity meetingNotice = meetingNoticeService.getById(noticeId);

        return R.ok().put("meetingNotice", meetingNotice);
    }


    /**
     * 消息发布
     */
    @ApiOperation("消息发布")
    @PutMapping("/publish")
    public R save(@RequestBody MeetingNoticeEntitySaveVO meetingNoticeEntitySaveVO){

        System.out.println(meetingNoticeEntitySaveVO);

		meetingNoticeService.publish(meetingNoticeEntitySaveVO);

        return R.ok();
    }

    /**
     * 附件上传
     */
    @ApiOperation("附件上传")
    @PostMapping("/upload")
    public R save(@RequestParam("file") MultipartFile[] files, HttpServletRequest request, HttpServletResponse response) throws FileNotFoundException {

        String s = UploadFileUtils.szhyFileSave(files,request,response);

        return R.ok().put("data",s);
    }

    /**
     * 修改
     */
    @ApiOperation("消息内容修改")
    @PostMapping("/update")
    public R update(@RequestBody MeetingNoticeEntitySaveVO meetingNoticeEntitySaveVO){

        System.out.println("MeetingNoticeController.update" + meetingNoticeEntitySaveVO);

		meetingNoticeService.updateByNoticeId(meetingNoticeEntitySaveVO);

        return R.ok();
    }

    /**
     * 删除
     */
    @ApiOperation("消息删除")
    @DeleteMapping("/delete")
    public R delete(@RequestBody String[] noticeIds){

        System.out.println(noticeIds.toString());

        meetingNoticeService.removeByNoticeIds(Arrays.asList(noticeIds));


        return R.ok();


    }

}
